#include "widget.h"
#include "ui_widget.h"

#include <QComboBox>
#include <QDebug>
#include <fstream>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // 1.模拟点餐
    // Order();

    // 2.从文件中加载下拉框中的选项
    Load();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::Load()
{
    std::ifstream file("F:/1.Code_Library/QtCode/QComboBox/Config.txt");
    if(!file.is_open())
    {
        qDebug() << "文件打开失败";
        return;
    }

    std::string line;
    while(std::getline(file, line))
    {
        ui->comboBox_4->addItem(QString::fromStdString(line));
    }

    file.close();
}



void Widget::Order()
{
    ui->comboBox->addItem("鸡肉汉堡");
    ui->comboBox->addItem("牛肉汉堡");

    ui->comboBox_2->addItem("薯条");
    ui->comboBox_2->addItem("鸡块");

    ui->comboBox_3->addItem("可乐");
    ui->comboBox_3->addItem("雪碧");
}

void Widget::on_pushButton_clicked()
{
    qDebug() << "汉堡选择：" << ui->comboBox->currentText();
    qDebug() << "小食选择：" << ui->comboBox_2->currentText();
    qDebug() << "饮料选择：" << ui->comboBox_3->currentText();
}
